//
//  LSZRequestData.m
//  PartyClassCloud
//
//  Created by 梁素珍 on 2018/8/13.
//  Copyright © 2018年 九酷. All rights reserved.
//

#import "LSZRequestData.h"

@implementation LSZRequestData
 
#pragma mark - 上传文件
+(void)UploadFile:(NSString *)file imageView:(UIImage *)imageViewStr :(HTTPString)block
{
    NSString * url = [NSString stringWithFormat:@"%@%@",URLTotal,@"/upload/file"];
   AFHTTPSessionManager * _manager = [AFHTTPSessionManager manager] ;
    _manager.responseSerializer.acceptableContentTypes = [NSSet setWithObjects:@"application/json",@"text/html",@"image/jpeg",@"image/png",@"image/jpg",@"application/octet-stream",@"text/json",nil] ;
    _manager.requestSerializer  = [AFHTTPRequestSerializer serializer ] ;
    _manager.responseSerializer = [AFHTTPResponseSerializer serializer] ;
    NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
    NSString *result = NullStringjudgment([defaults objectForKey:@"token"]);
    [_manager.requestSerializer setValue:result forHTTPHeaderField:@"Auth-Token"];
    [_manager POST:url parameters:nil constructingBodyWithBlock:^(id<AFMultipartFormData>  _Nonnull formData)
     {
         NSString *fileName = [NSString stringWithFormat:@"%@",file] ;
         //压缩图片
         //_imageEdit是从相机获取的图片
         NSData *imageData = UIImageJPEGRepresentation(imageViewStr, 0.2) ;
         //上传图片到服务器
         [formData appendPartWithFileData:imageData name:@"file" fileName:[fileName lastPathComponent] mimeType:@"image/jpg"];
     }
     //上传过程中调用
          progress:^(NSProgress * _Nonnull uploadProgress)
     {
     }
     //上传成功调用
           success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject)
     {
         NSString *result =[[NSString alloc] initWithData:responseObject encoding:NSUTF8StringEncoding];

         block(YES,@"上传成功!",result);
     }
           failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error)
     {
         block(NO,@"上传失败!",nil);
     }] ;
}
#pragma mark - 把头像url上传服务器
+(void)initWithUploadTheAvatarUrlToTheServer:(NSString *)stirng :(HTTPString)block
{
//    NSMutableDictionary * dic = [[NSMutableDictionary alloc]initWithObjectsAndKeys:stirng,@"headUrl",[_MyCenter my_id],@"id", nil];
//    NSString * string = [NSString stringWithFormat:@"%@",@"/customer"];
    
//    NSMutableDictionary * dic = [[NSMutableDictionary alloc]initWithObjectsAndKeys:[NSString stringWithFormat:@"%@%@",URLTotalWeb,stirng],@"headUrl",[_MyCenter my_id],@"id", nil];
    NSMutableDictionary * dic = [[NSMutableDictionary alloc]initWithObjectsAndKeys:stirng,@"headUrl",[_MyCenter my_id],@"id", nil];
    NSString * str = [NSString stringWithFormat:@"%@",@"/customer"];
    [LSZTotalRequest initWithPostNoEncryptionRequest:str :dic :^(BOOL isOk, NSString * string, id diction) {
        if (isOk == YES) {
            block(YES,@"",diction);
        }else{
            block(NO,string,nil);
        }
    }];
}
#pragma mark - 提交问题｛”content”:””,” coverUrl”:””｝
+(void)submitQuestions:(NSString *)content coverUrl:(NSString *)coverUrl :(HTTPDic)block
{
    NSMutableDictionary * dic = [[NSMutableDictionary alloc]init];
    [dic setObject:[NSString stringWithFormat:@"%@",content] forKey:@"content"];
    if (![coverUrl isEqualToString:@""]) {
        [dic setObject:coverUrl forKey:@"coverUrl"];
    }
    [LSZTotalRequest initWithPostNoEncryptionRequestThreeLesson:@"/question" :dic :^(BOOL isOK, NSString * string, id diction) {
        if (isOK == YES) {
            block(YES,string,diction);
        }else{
            block(NO,string,diction);
        }
    }];
    
    
    

//    [LSZTotalRequest initWithPostNoEncryptionRequest:@"/question" :dic :^(BOOL isOk, NSString * string, id diction) {
//        if (isOk == YES) {
//            block(YES,@"",diction);
//        }else{
//            block(NO,string,nil);
//        }
//    }];
    //initWithGetNoEncryptionRequest
}
#pragma mark - 个人中心
+(void)initWithPersonalCenter:(HTTPDic)block
{
    NSMutableDictionary * dic = [[NSMutableDictionary alloc]init];
    NSString * string = [NSString stringWithFormat:@"%@",@"/customer"];
    [LSZTotalRequest initWithGetNoEncryptionRequest:string :dic :^(BOOL isOk, NSString * string, id diction) {
        if (isOk == YES) {
            [_MyCenter setMy_id:NullStringjudgment(NSStr(diction[@"id"]))];
            [_MyCenter setRealName:NullStringjudgment(NSStr(diction[@"name"]))];
            [_MyCenter setMobilePhone:NullStringjudgment(NSStr(diction[@"contactPhone"]))];
            [_MyCenter setBranch_name:NullStringjudgment(NSStr(diction[@"jobLabel"]))];
            [_MyCenter setBranch_id:NullStringjudgment(NSStr(diction[@"branchId"]))];
            [_MyCenter setSex:NullStringjudgment(NSStr(diction[@"sex"]))];
            [_MyCenter setDepartmentScore:NullStringjudgment(NSStr(diction[@"score"]))];
            [_MyCenter setHeadUrl:[NSString stringWithFormat:@"%@%@",URLTotalWeb,diction[@"headUrl"]]];
            [_MyCenter setMyHours:NSStr(diction[@"hours"])];
            [_MyCenter setBranchName:NullStringjudgment(NSStr(diction[@"branchName"]))];
            [_MyCenter setMyJobId:NSStr(diction[@"jobId"])];
            if ([[diction allKeys] containsObject:@"account"]) {
                NSDictionary * dic = diction[@"account"];
                if ([[dic allKeys] containsObject:@"role"]) {
                    id role = dic[@"role"];
                    if ([role isKindOfClass:[NSDictionary class]]) {
                        [_MyCenter setRoleId:role[@"id"]];
                    }
                }
            }
            block(YES,@"",diction);
        }else{
            block(NO,string,nil);
        }
    }];
}
#pragma mark - 获取大数据_党员人数
+(void)initWithTheNumberParty :(HTTPString)block
{
    NSMutableDictionary * dic = [[NSMutableDictionary alloc]init];
    NSString * string = [NSString stringWithFormat:@"%@",@"/customer/total"];
    [LSZTotalRequest initWithGetNoEncryptionRequestReturnStr:string :dic :^(BOOL isOk, NSString * string, id diction) {
        if (isOk == YES) {
            block(YES,@"",diction);
        }else{
            block(NO,string,nil);
        }
    }];
}
#pragma mark - 获取大数据_支部人数
+(void)initWithThenumberBranch :(HTTPString)block
{
    NSMutableDictionary * dic = [[NSMutableDictionary alloc]init];
    NSString * string = [NSString stringWithFormat:@"%@",@"/branch/leaf/total"];
    [LSZTotalRequest initWithGetNoEncryptionRequestReturnStr:string :dic :^(BOOL isOk, NSString * string, id diction) {
        if (isOk == YES) {
            block(YES,@"",diction);
        }else{
            block(NO,string,nil);
        }
    }];
}
#pragma mark - 获取大数据_12个月的学习情况
+(void)initWithTheLearningSituation :(HTTPString)block
{
    NSMutableDictionary * dic = [[NSMutableDictionary alloc]init];
    NSString * string = [NSString stringWithFormat:@"%@",@"/activity/12months"];
    [LSZTotalRequest initWithGetNoEncryptionRequestReturnStr:string :dic :^(BOOL isOk, NSString * string, id diction) {
        if (isOk == YES) {
            block(YES,@"",diction);
        }else{
            block(NO,string,nil);
        }
    }];
}
#pragma mark - 修改性别
+(void)initWithModifyTheGender:(NSString *)gender :(HTTPString)block
{
    NSMutableDictionary * dic = [[NSMutableDictionary alloc]initWithObjectsAndKeys:gender,@"sex",[_MyCenter my_id],@"id", nil];
    NSString * string = [NSString stringWithFormat:@"%@",@"/customer"];
    [LSZTotalRequest initWithGetNoEncryptionRequestReturnStr:string :dic :^(BOOL isOk, NSString * string, id diction) {
        if (isOk == YES) {
            block(YES,@"",diction);
        }else{
            block(NO,string,nil);
        }
    }];
}
#pragma mark- 删除收藏
+(void)initWithDeleteTheCollection:(NSString *)id_id :(HTTPString)block
{
    NSMutableDictionary * dic = [[NSMutableDictionary alloc]init];
    NSString * string = [NSString stringWithFormat:@"%@?resourceId=%@",@"/resource/_favor/cancel",id_id];
    [LSZTotalRequest initWithPostNoEncryptionRequest:string :dic :^(BOOL isOk, NSString * string, id diction) {
        if (isOk == YES) {
            block(YES,@"",diction);
        }else{
            block(NO,string,nil);
        }
    }];
}
#pragma mark - 收藏
+(void)initTheArticleCollects:(NSString *)id_id :(HTTPDic)block
{
    NSMutableDictionary * dic = [[NSMutableDictionary alloc]initWithObjectsAndKeys:id_id,@"resourceId", nil];
    NSString * string = @"/resource/_favor";
    [LSZTotalRequest initWithPostNoEncryptionRequest:string :dic :^(BOOL isOk, NSString * string, id diction) {
        if (isOk == YES) {
            block(YES,@"",diction);
        }else{
            block(NO,string,nil);
        }
    }];
}
#pragma mark - 满60分提交数据
+(void)initWithPassTheData :(NSString *)paperId :(NSString *)mark :(HTTPDic)block
{
    NSMutableDictionary * dic = [[NSMutableDictionary alloc]initWithObjectsAndKeys:mark,@"mark", nil];
//    NSString * string = [NSString stringWithFormat:@"%@%@",@"/paper/_exam",paperId];
    ///paper/_exam?score=80&paperId=id&period=80
    NSString * string = [NSString stringWithFormat:@"%@?score=%@&&paperId=%@&&period=%@",@"/paper/_exam",mark,paperId,@"80"];
    [LSZTotalRequest initWithPostNoEncryptionRequest:string :dic :^(BOOL isOk, NSString * string, id diction) {
        if (isOk == YES) {
            block(YES,@"",diction);
        }else{
            block(NO,string,nil);
        }
    }];
}
#pragma mark - 对问题进行答复
+(void)initWithAnswerQuestions :(NSString *)paperId  content:(NSString*)content :(HTTPDic)block
{
    NSMutableDictionary * dic = [[NSMutableDictionary alloc]initWithObjectsAndKeys:content,@"content",paperId,@"questionId",nil];
    NSString * string = [NSString stringWithFormat:@"%@",@"/answer"];
    [LSZTotalRequest initWithPostNoEncryptionRequestThreeLesson:string :dic :^(BOOL isOk, NSString * string, id diction) {
        if (isOk == YES) {
            block(YES,@"",diction);
        }else{
            block(NO,string,nil);
        }
    }];
}
#pragma mark - 修改密码
+(void)initWithChangeThePassword:(NSString *)oldPassword :(NSString *)newPassword :(HTTPString)block
{
    NSMutableDictionary * dic = [[NSMutableDictionary alloc]initWithObjectsAndKeys:oldPassword,@"oldPassword",newPassword,@"newPassword", nil];
    NSString * string = [NSString stringWithFormat:@"%@",@"/account/_put/pwd"];
    [LSZTotalRequest initWithPostNoEncryptionRequestReturnStr:string :dic :^(BOOL isOk, NSString * string, id str) {
        if(isOk == YES){
            NSString * String = NullStringjudgment(NSStr(str));
            if(String.length > 0){
                NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
                [defaults setObject:str forKey:@"token"];
                [defaults synchronize];
                block(YES,string,str);
            }else{
                block(NO,@"原密码输入有问题,请重试!",str);
            }
        }else{
            block(NO,string,nil);
        }
    }];
}
#pragma mark - 删除三会一课
+(void)initWithDeleteThreeSessionsLesson:(NSString *)id_id :(HTTPString)block
{
    NSMutableDictionary * dic = [[NSMutableDictionary alloc]init];
    NSString * string = [NSString stringWithFormat:@"%@%@%@",@"/activity/_del/",id_id,@"/self"];
    [LSZTotalRequest initWithPostNoEncryptionRequestReturnStr:string :dic :^(BOOL isOk, NSString * str, id Str) {
        if (isOk == YES) {
            block(YES,string,str);
        }else{
            block(NO,string,nil);
        }
    }];
}
#pragma mark - 发布帮扶日志 id_id帮扶人
+(void)initWithPublishThreeMeetingsOneLesson:(NSString *)subject activityTime:(NSString *)activityTime address:(NSString *)address content:(NSString *)content coverUrl:(NSString *)coverUrl id_id:(NSString *)id_id personNames:(NSString *)personNames :(HTTPString)block
{
    NSMutableDictionary * dic = [[NSMutableDictionary alloc]initWithObjectsAndKeys:subject,@"subject",activityTime,@"activityTime",address,@"address",content,@"content",coverUrl,@"coverUrl",id_id,@"catalog", nil];
    NSString * str = [NSString stringWithFormat:@"/poverty/diary?householdId=%@",[_MyCenter my_id]];
    [LSZTotalRequest initWithPostNoEncryptionRequestThreeLesson:str :dic :^(BOOL isOK, NSString * string, id dic) {
        if (isOK == YES) {
            block(YES,string,nil);
        }else{
            block(NO,string,nil);
        }
    }];
}
#pragma mark - 发布项目管理
+(void)initWithReleaseIndustryManagement:(NSString *)subject activityTime:(NSString *)activityTime personNames:(NSString *)personNames content:(NSString *)content coverUrl:(NSString *)coverUrl :(HTTPString)block
{
    NSMutableDictionary * dic = [[NSMutableDictionary alloc]initWithObjectsAndKeys:subject,@"subject",activityTime,@"activityTime" ,personNames,@"personNames",content,@"content",coverUrl,@"coverUrl", nil];
    [LSZTotalRequest initWithPostNoEncryptionRequestThreeLesson:@"/activity/industry" :dic :^(BOOL isOK, NSString * string, id dic) {
        if (isOK == YES) {
            block(YES,string,nil);
        }else{
            block(NO,string,nil);
        }
    }];
}
#pragma mark - 互助自己的问题点击变成已解决
+(void)theProblemMutualAssistanceBecomeSolved:(NSString *)id_id :(HTTPString)block
{
    NSMutableDictionary * dic = [[NSMutableDictionary alloc]init];
    NSString * string = [NSString stringWithFormat:@"%@?questionId=%@",@"/question/_solve",id_id];
    [LSZTotalRequest initWithPostNoEncryptionRequestReturnStr:string :dic :^(BOOL isOk, NSString * str, id Str) {
        if (isOk == YES) {
            block(YES,str,Str);
        }else{
            block(NO,str,nil);
        }
    }];
}
#pragma mark - 互助删除自己发布的问题
+(void)mutualDeletionTheirOwnIssues:(NSString *)id_id :(HTTPString)block
{
    NSMutableDictionary * dic = [[NSMutableDictionary alloc]init];
    NSString * string = [NSString stringWithFormat:@"%@?questionId=%@",@"/question/_del/",id_id];
    [LSZTotalRequest initWithPostNoEncryptionRequestReturnStr:string :dic :^(BOOL isOk, NSString * str, id Str) {
        if (isOk == YES) {
            block(YES,str,Str);
        }else{
            block(NO,str,nil);
        }
    }];
}
#pragma mark - 文章看 向后台记录
+(void)completeDocumentation:(NSString *)period paperId:(NSString *)paperId :(HTTPString)block
{
    NSString * strUrl = [[NSString alloc]init];
    NSMutableDictionary * dic = [[NSMutableDictionary alloc]init];
    if ([period isEqualToString:@"0"]) {
        //资讯
        strUrl = [NSString stringWithFormat:@"/resource/_hour?hour=20&resourceId=%@",paperId];
    }else{
        dic = [[NSMutableDictionary alloc]initWithObjectsAndKeys:period,@"period", nil];
        strUrl = [NSString stringWithFormat:@"/chapter/record/%@",paperId];
    }
    [LSZTotalRequest initWithPostNoEncryptionRequestReturnStr:strUrl :dic :^(BOOL isOk, NSString * str, id Str) {
        if (isOk == YES) {
            block(YES,str,Str);
        }else{
            block(NO,str,nil);
        }
    }];
}
#pragma mark- 音视频完成90秒
+(void)WatchAudioAndVideoFinished:(NSString *)period paperId:(NSString *)paperId :(HTTPString)block
{
    NSMutableDictionary * dic = [[NSMutableDictionary alloc]initWithObjectsAndKeys:period,@"period", nil];
    NSString * strUrl = [NSString stringWithFormat:@"/chapter/record/%@",paperId];;
    [LSZTotalRequest initWithPostNoEncryptionRequestReturnStr:strUrl :dic :^(BOOL isOk, NSString * str, id Str) {
        if (isOk == YES) {
            block(YES,str,Str);
        }else{
            block(NO,str,nil);
        }
    }];
}
#pragma mark - 检测版本更新
+(void)detectionVersionUpdate:(HTTPDic)block
{
    NSMutableDictionary * dic = [[NSMutableDictionary alloc]init];
    NSString * string = [NSString stringWithFormat:@"%@",@"/version/09e3e39c88b34ff68e29e658fe7d41a2"];
    [LSZTotalRequest initWithGetNoEncryptionRequest:string :dic :^(BOOL isOk, NSString * string, id diction) {
        NSLog(@"%@>>>>>>",diction);
        if (isOk == YES) {
            block(YES,@"",diction);
        }else{
            block(NO,string,nil);
        }
    }];
}

#pragma mark - /activity/secretary/list
+(void)initRiZhi:(HTTPDic)block
{
    NSMutableDictionary * dic = [[NSMutableDictionary alloc]init];
    NSString * string = [NSString stringWithFormat:@"%@",@"/activity/secretary/list"];
    [LSZTotalRequest initWithGetNoEncryptionRequest:string :dic :^(BOOL isOk, NSString * string, id diction) {
        NSLog(@"%@>>>>>>",diction);
        if (isOk == YES) {
            block(YES,@"",diction);
        }else{
            block(NO,string,nil);
        }
    }];
}
#pragma mark - 获取所在的村
+(void)initResGetMyVillage:(HTTPDic)block
{
    NSMutableDictionary * dic = [[NSMutableDictionary alloc]init];
    NSString * string = [NSString stringWithFormat:@"%@",@"/branch/top1"];
    [LSZTotalRequest initWithGetNoEncryptionRequest:string :dic :^(BOOL isOk, NSString * string, id diction) {
        NSLog(@"%@>>>>>>",diction);
        if (isOk == YES) {
            if([diction[@"leaf"] isEqualToString:@"false"]){
                [_UserM setVillageID:NullStringjudgment(NSStr(diction[@"id"]))];
                [_UserM setVillageIDState:NullStringjudgment(NSStr(diction[@"leaf"]))];
                block(YES,@"",diction);

            }else{
                [_UserM setLeaf:@""];
                block(NO,@"",diction);
            }
         }else{
            block(NO,string,nil);
        }
    }];
}
#pragma mark - 学习时长
+(void)theLearningTime:(HTTPString)block
{
    NSMutableDictionary * dic = [[NSMutableDictionary alloc]init];
//    NSString * string = [NSString stringWithFormat:@"%@",@"/dj/chapter/record/period/self"];
    NSString * string = [NSString stringWithFormat:@"%@",@"/paper/list/record"];
    ///dj/exam/result/self  /paper/list/score
    [LSZTotalRequest initWithGetNoEncryptionRequestReturnStr:string :dic :^(BOOL isOk, NSString * string, id diction) {
        if (isOk == YES) {
            block(YES,@"",diction);
        }else{
            block(NO,string,nil);
        }
    }];
}
#pragma mark - 帮扶责任人
+(void)helpTheResponsiblePerson:(NSString *)customerId :(HTTPDic)block
{
    NSMutableDictionary * dic = [[NSMutableDictionary alloc]init];
    NSString * string = [NSString stringWithFormat:@"/customer/id?customerId=%@",customerId];
    [LSZTotalRequest initWithGetNoEncryptionRequest:string :dic :^(BOOL isOk, NSString * string, id diction) {
        if (isOk == YES) {
            block(YES,@"",diction);
        }else{
            block(NO,string,nil);
        }
    }];
}
#pragma mark - 提交帮扶日志
+(void)initWithSubmitTheHelpLog:(NSString *)customerId subject:(NSString *)subject activityTime:(NSString *)activityTime address:(NSString *)address personNames:(NSString *)personNames content:(NSString *)content coverUrl:(NSString *)coverUrl :(HTTPDic)block
{
    NSMutableDictionary * dic = [[NSMutableDictionary alloc]initWithObjectsAndKeys:subject,@"subject",activityTime,@"activityTime",address,@"address",personNames,@"personNames",content,@"content",coverUrl,@"coverUrl", nil];
    NSString * string = [NSString stringWithFormat:@"/poverty/diary?householdId=%@",customerId];
    [LSZTotalRequest initWithGetNoEncryptionRequest:string :dic :^(BOOL isOk, NSString * string, id diction) {
        if (isOk == YES) {
            block(YES,@"",diction);
        }else{
            block(NO,string,nil);
        }
    }];
}
#pragma mark - 通知信息确认
+(void)notificationConfirmation:(NSString *)activityId :(HTTPDic)block
{
    NSMutableDictionary * dic = [[NSMutableDictionary alloc]init];
    NSString * string = [NSString stringWithFormat:@"/activity/task/_check?activityId=%@",activityId];
    [LSZTotalRequest initWithPostNoEncryptionRequest:string :dic :^(BOOL isOk, NSString * string, id diction) {
        if (isOk == YES) {
            block(YES,@"确认成功!",diction);
        }else{
            block(NO,string,nil);
        }
    }];
}
#pragma mark - 反馈信息
+(void)feedbackInformation:(NSString *)activityId :(NSString *)content :(HTTPDic)block
{
    NSMutableDictionary * dic = [[NSMutableDictionary alloc]init];
    NSString * string = [NSString stringWithFormat:@"/activity/task/_feedback?activityId=%@&content=%@",activityId,content];
    [LSZTotalRequest initWithPostNoEncryptionRequest:string :dic :^(BOOL isOk, NSString * string, id diction) {
        if (isOk == YES) {
            block(YES,@"",diction);
        }else{
            block(NO,string,nil);
        }
    }];
}
#pragma mark - 签到
+(void)usersCheckIn:(NSString *)address :(HTTPDic)block
{
    NSMutableDictionary * dic = [[NSMutableDictionary alloc]init];
    NSString * string = [NSString stringWithFormat:@"/sign?address=%@",address];
    [LSZTotalRequest initWithPostNoEncryptionRequest:string :dic :^(BOOL isOk, NSString * string, id diction) {
        if (isOk == YES) {
            block(YES,@"",diction);
        }else{
            block(NO,string,nil);
        }
    }];
}
@end
